package com.example.testapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
import androidx.lifecycle.ReportFragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;

import com.example.testapplication.JetPact.MyOberver;

public class xueJetpackLifecycle extends Activity implements LifecycleOwner {

    LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);

    @SuppressLint("RestrictedApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xue_jetpack_lifecycle);
        ReportFragment.injectIfNeededIn(this);
        // 添加监听
        getLifecycle().addObserver(new MyOberver());
    }

    @NonNull
    @Override
    public Lifecycle getLifecycle() {
        return lifecycleRegistry;
    }
}